package cn.iocoder.yudao.module.book.controller.app;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.book.controller.app.vo.AssignmentsByClassIdRespVO;
import cn.iocoder.yudao.module.book.controller.app.vo.BookSchoolAssignmentSaveReqVO;
import cn.iocoder.yudao.module.book.service.app.BookSchoolAssignmentService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.websocket.server.PathParam;

@RestController
@RequestMapping("/bookSchoolAssignment")
@Validated
public class BookSchoolAssignmentController {

    @Resource
    private BookSchoolAssignmentService bookSchoolAssignmentService;

    @PostMapping("/createBookSchoolAssignment")
    @Operation(summary = "创建作业")
//    @PreAuthorize("@ss.hasPermission('book:bookSchoolAssignment:createBookSchoolAssignment')")
    public CommonResult<Void> createBookSchoolAssignment(@Validated @RequestBody BookSchoolAssignmentSaveReqVO bookSchoolAssignmentSaveReq) {
        bookSchoolAssignmentService.createBookSchoolAssignment(bookSchoolAssignmentSaveReq);
        return CommonResult.success(null);
    }

    @PutMapping("/updateBookSchoolAssignment")
    @Operation(summary = "更新作业")
//    @PreAuthorize("@ss.hasPermission('book:bookSchoolAssignment:updateBookSchoolAssignment')")
    public void updateBookSchoolAssignment(@Validated @RequestBody BookSchoolAssignmentSaveReqVO bookSchoolAssignmentSaveReq) {
        bookSchoolAssignmentService.updateBookSchoolAssignment(bookSchoolAssignmentSaveReq);
    }

    @DeleteMapping("/deleteBookSchoolAssignment/{id}")
    @Operation(summary = "删除作业")
//    @PreAuthorize("@ss.hasPermission('book:bookSchoolAssignment:deleteBookSchoolAssignment')")
    public void deleteBookSchoolAssignment(@PathVariable Long id) {
        bookSchoolAssignmentService.deleteBookSchoolAssignment(id);
    }

    @GetMapping("/getAssignmentsByClassId")
    @Operation(summary = "根据班级ID获取作业列表")
    public CommonResult<List<AssignmentsByClassIdRespVO>> getAssignmentsByClassId(@PathParam("classId") String classId) {
        return CommonResult.success(bookSchoolAssignmentService.getAssignmentsByClassId(classId));
    }

    @GetMapping("/getAssignmentDetailsById")
    @Operation(summary = "根据作业ID获取作业详情")
    public CommonResult<AssignmentsByClassIdRespVO> getAssignmentDetailsById(@PathParam("id") String id) {
        return CommonResult.success(bookSchoolAssignmentService.getAssignmentDetailsById(id));
    }

}